/* .net 代理接口 */
import querystring from '@/modules/corejs/url/search-string'
import axios from 'axios'

let proxyServer = '/Mccard/ClassBrand/GetCommonDataSetUrl'
let interfaceServer = ''

if (process.env.NODE_ENV !== 'production') {
  proxyServer = require('@/mock.config').default.baseUrl + proxyServer

  // interfaceServer = 'http://192.168.1.240:8116'
  interfaceServer = ''
}

function urlHandle (url) {
  // return url.replace(/^\/classcard\/v1/, '')
  return url
}

export default {
  request (config) {
    if (config.method === 'get') return this.get(config.url, config)
    this.post(config.url, config.data, config)
  },
  get (url, { params } = {}) {
    url = urlHandle(url)
    if (params) {
      params = '?' + querystring(params)
    } else {
      params = ''
    }
    url = interfaceServer + url + params
    if (process.env.NODE_ENV !== 'production') {
      proxyServer = proxyServer.replace(/\?.+/, '')
      proxyServer += '?url=' + url
    }
    return axios.post(proxyServer, {
      url,
      method: 'get'
    })
  },
  post (url, data) {
    url = urlHandle(url)
    if (process.env.NODE_ENV !== 'production') {
      proxyServer = proxyServer.replace(/\?.+/, '')
      proxyServer += '?url=' + url
    }
    return axios.post(proxyServer, {
      url: interfaceServer + url,
      method: 'post',
      params: JSON.stringify(data)
    })
  }
}
